<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" id="bdForm" style="margin-left: 10%">
    <input name="bdTeamId" id="bdTeamId" type="hidden"/>
    <br/>
    <div class="layui-form-item" style="margin-left: 15%">
        <label class="layui-form-label">会员类型</label>
        <div class="layui-input-inline">
            <select name="vipLevel" id="vipLevel" lay-verify="required">
                <option value="1">试用会员</option>
                <option value="2">任享会员</option>
                <option value="3">畅享会员</option>
                <option value="4">季卡会员</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="margin-left: 15%">
        <label class="layui-form-label">兑换码张数:</label>
        <div class="layui-input-inline">
            <input type="text" name="amount" id="amount" lay-verify="required|number" placeholder="请输入备注"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="margin-left: 15%">
        <label class="layui-form-label">备注:</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" id="remark" lay-verify="required" placeholder="请输入备注"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <button class="layui-btn" id="formSubmit" lay-submit="" lay-filter="formSubmit" style="display: none">立即提交</button>
</form>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var successCallback;
    var bdTeamId = getQueryString("bdTeamId");
    $("#bdTeamId").val(bdTeamId);

    //监听提交
    form.on('submit(formSubmit)', function (data) {
        if ($("#amount").val() >= 500) {
            layer.msg('一次性生成的兑换码数量不能超过500');
        } else {
            $.post('/backend/security/bdTeamCode/addCodeLog', data.field, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    layer.msg('操作成功');
                    successCallback && successCallback();
                    parent.tableIns.reload();
                }
            });
        }
        return false;
    });

    var formSubmit = function (callback) {
        successCallback = callback;
        $("#formSubmit").click();
    }


    $(function () {

    })
</script>
</body>
</html>
